<template>
	<div class="app-container">
		<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="72px"
			class="queryForms">
			<el-form-item label="任务单号" prop="repairNumber">
				<el-input v-model="queryParams.repairNumber" placeholder="请输入任务单号" clearable
					@keyup.enter.native="handleQuery" maxlength="20" show-word-limit />
			</el-form-item>
			<el-form-item label="状态" prop="malfunctionStatus">
				<el-select v-model="queryParams.malfunctionStatus" placeholder="请选择">
					<el-option v-for="dict in dict.type.fault_status" :key="dict.value" :label="dict.label"
						:value="dict.value"> </el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="产品名称" prop="productName">
				<el-input v-model="queryParams.productName" placeholder="请输入产品名称" clearable
					@keyup.enter.native="handleQuery" maxlength="20" show-word-limit />
			</el-form-item>
			<el-form-item label="产品型号" prop="productModel">
				<el-input v-model="queryParams.productModel" placeholder="请输入产品型号" clearable
					@keyup.enter.native="handleQuery" maxlength="20" show-word-limit />
			</el-form-item>
			<el-form-item label="产品编号" prop="productNumber">
				<el-input v-model="queryParams.productNumber" placeholder="请输入产品编号" clearable
					@keyup.enter.native="handleQuery" maxlength="20" show-word-limit />
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
				<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
			</el-form-item>
		</el-form>
		<el-row :gutter="10" class="mb8">
			<right-toolbar menuNames="RedundantController49" @changeTableData="changeTableData"
				:showSearch.sync="showSearch" @queryTable="handleQuery" :columns.sync="columns"
				perm="RedundantController:RedundantController:index"></right-toolbar>
		</el-row>
		<div :class="sidebar.opened && eleTabTop <= 85 ? 'eleTab' : !sidebar.opened && eleTabTop <= 85 ? 'eleTabs' : ''"
			class="informationTab" ref="eleTab">
			<el-table :row-class-name="row_class_name" @mousedown.native="mousedownTable" @row-click="row_click"
				@cell-mouse-enter="cell_mouse_enter" @cell-mouse-leave="cell_mouse_leave" @mouseup.native="mouseupTable"
				@mouseleave.native="mouseupTable" ref="table" v-loading="loading"
				@selection-change="handleSelectionChange" :data="FaultList" row-key="id" lazy :load="loadListDes"
				:tree-props="{ children: 'children', hasChildren: 'hasChildren' }" border height="100%">
				<el-table-column type="selection" width="55" align="center" />
				<el-table-column label="序号" align="center" type="index" width="55">
					<template slot-scope="scope">
						<div>{{ scope.row.sort }}</div>
					</template>
				</el-table-column>
				<el-table-column label="返修任务单" prop="repairNumber" min-width="250" :show-overflow-tooltip="true"
					v-if="columns[0].visible" />
				<el-table-column label="客户代表" prop="productRepresentativeName" min-width="150"
					:show-overflow-tooltip="true" v-if="columns[1].visible" />
				<el-table-column label="用户" prop="clientName" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[2].visible" />
				<el-table-column label="产品名称" prop="productName" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[3].visible" />
				<el-table-column label="产品型号" prop="productModel" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[4].visible" />
				<el-table-column label="产品编号" prop="productNumber" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[5].visible" />
				<el-table-column label="产品数量" align="center" prop="productQuantity" min-width="150"
					:show-overflow-tooltip="true" v-if="columns[6].visible" />
				<el-table-column label="核实故障日期" align="center" prop="malfunctionVerifyTime" min-width="150"
					:show-overflow-tooltip="true" v-if="columns[7].visible" />
				<el-table-column label="维修类别" prop="maintenanceCategoryName" min-width="150"
					:show-overflow-tooltip="true" v-if="columns[8].visible" />
				<!-- 故障原因不显示 -->
				<!-- <el-table-column label="故障原因" prop="deviceTypeName" min-width="150" :show-overflow-tooltip="true" /> -->
				<el-table-column label="故障模式" prop="failureMode" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[9].visible" />
				<el-table-column label="故障核实情况" prop="failureRemark" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[10].visible" />
				<el-table-column label="状态" prop="malfunctionStatus" min-width="150" :show-overflow-tooltip="true"
					align="center" v-if="columns[11].visible">
					<template slot-scope="scope">
						<div v-if="scope.row.malfunctionStatus === '0'" style="color: #7ebf27">
							<dict-tag :options="dict.type.fault_status" :value="scope.row.malfunctionStatus" />
						</div>
						<div v-if="scope.row.malfunctionStatus === '1'" style="color: #e1756d">
							<dict-tag :options="dict.type.fault_status" :value="scope.row.malfunctionStatus" />
						</div>
						<div v-if="scope.row.malfunctionStatus === '2'" style="color: #63b0b3">
							<dict-tag :options="dict.type.fault_status" :value="scope.row.malfunctionStatus" />
						</div>
						<div v-if="scope.row.malfunctionStatus === '3'" style="color: #333">
							<dict-tag :options="dict.type.fault_status" :value="scope.row.malfunctionStatus" />
						</div>
					</template>
				</el-table-column>
				<el-table-column align="center" label="工艺通知单编号" prop="processNumber" min-width="150"
					:show-overflow-tooltip="true" v-if="columns[12].visible">
					<template slot-scope="scope">
						<div v-if="scope.row.hasChildren">
							<div v-if="scope.row.processNumber == 1" style="color: red">未上传</div>
							<div v-if="scope.row.processNumber == 2" style="color: orange">部分上传</div>
							<div v-if="scope.row.processNumber == 3" style="color: green">全部上传</div>
						</div>
						<div v-else>
							{{ scope.row.processNumber }}
						</div>
					</template>
				</el-table-column>
				<el-table-column label="审批状态" prop="malfunctionApprovalStatus" min-width="150" align="center"
					:show-overflow-tooltip="true" v-if="columns[13].visible">
					<template slot-scope="scope">
						<el-tag type="info" v-if="scope.row.malfunctionApprovalStatus === '0'" class="disableClick">
							<dict-tag :options="dict.type.default_approve"
								:value="scope.row.malfunctionApprovalStatus" />
						</el-tag>
						<el-tag v-if="scope.row.malfunctionApprovalStatus === '1'" @click="showApproveList(scope.row)"
							class="clickable">
							<dict-tag :options="dict.type.default_approve"
								:value="scope.row.malfunctionApprovalStatus" />
						</el-tag>
						<el-tag type="success" v-if="scope.row.malfunctionApprovalStatus === '2'"
							@click="showApproveList(scope.row)" class="clickable">
							<dict-tag :options="dict.type.default_approve"
								:value="scope.row.malfunctionApprovalStatus" />
						</el-tag>
						<el-tag type="danger" v-if="scope.row.malfunctionApprovalStatus === '3'"
							@click="showApproveList(scope.row)" class="clickable">
							<dict-tag :options="dict.type.default_approve"
								:value="scope.row.malfunctionApprovalStatus" />
						</el-tag>
					</template>
				</el-table-column>
				<el-table-column label="操作" class-name="small-padding fixed-width" width="240px" fixed="right">
					<template slot-scope="scope">
						<section v-if="scope.row.hasChildren">
							<el-button size="mini" type="text" icon="el-icon-view" @click="handleControl(scope.row)"
								v-hasPermi="['RedundantController:RedundantController:detailcomponents']">多余控制物</el-button>
							<el-button size="mini" type="text" icon="el-icon-edit" @click="handleDetail(scope.row)"
								v-hasPermi="['RedundantController:RedundantController:detail']">详情</el-button>
							<el-button size="mini" type="text" icon="el-icon-wallet" @click="handleAnnex(scope.row)"
								v-hasPermi="['RedundantController:RedundantController:annex']">附件</el-button>
						</section>
						<section v-else>
							<el-button size="mini" type="text" icon="el-icon-edit" @click="handleDetailChild(scope.row)"
								v-hasPermi="['RedundantController:RedundantController:detail2']">详情</el-button>
							<el-button size="mini" type="text" icon="el-icon-wallet" @click="handleAnnex2(scope.row)"
								v-hasPermi="['RedundantController:RedundantController:annex2']">附件</el-button>
						</section>
					</template>
				</el-table-column>
			</el-table>
		</div>
		<pagination menuNames="Pagination52" v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
			:limit.sync="queryParams.pageSize" @pagination="getList" />
		<!-- 故障核实对话框 -->
		<el-dialog :title="title" :visible.sync="open" width="900px" append-to-body v-dialogDrag>
			<el-form ref="form" :model="form" :rules="rules" label-width="120px" class="add-form2" :disabled="disabled">
				<div class="form-title">
					<span class="title-msg">基本信息</span>
				</div>
				<el-form-item label="返修任务单号" prop="repairNumber" v-show="form.id !== 0">
					<el-input v-model="form.repairNumber" disabled />
				</el-form-item>
				<el-form-item label="产品名称" prop="productName" v-show="form.id !== 0">
					<el-input v-model="form.productName" disabled />
				</el-form-item>
				<el-form-item label="产品型号" prop="productModel" v-show="form.id !== 0">
					<el-input v-model="form.productModel" disabled />
				</el-form-item>
				<el-form-item label="产品编号" prop="productNumber" v-show="form.id !== 0">
					<el-input v-model="form.productNumber" disabled />
				</el-form-item>
				<el-form-item label="产品接收日期" prop="receiptTime" v-show="form.id !== 0">
					<el-input v-model="form.receiptTime" disabled />
				</el-form-item>
				<div v-show="form.id !== 0"></div>
				<el-form-item label="故障核实日期" prop="malfunctionVerifyTime">
					<el-date-picker v-model="form.malfunctionVerifyTime" type="date" value-format="yyyy-MM-dd"
						placeholder="请选择"> </el-date-picker>
				</el-form-item>
				<el-form-item label="维修类别" prop="maintenanceCategoryId">
					<el-select v-model="form.maintenanceCategoryId" placeholder="请选择" @change="changeCat">
						<el-option v-for="dict in dict.type.maintain_cat" :key="dict.value" :label="dict.label"
							:value="dict.value"> </el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="故障模式" prop="failureMode" style="width: 100%">
					<el-input v-model="form.failureMode" type="textarea" disabled />
				</el-form-item>
				<div class="form-title">
					<span class="title-msg">核实情况</span>
				</div>
				<el-form-item label="状态" prop="malfunctionStatus" style="width: 100%">
					<el-radio v-model="form.malfunctionStatus" label="0">核实无故</el-radio>
					<el-radio v-model="form.malfunctionStatus" label="1">核实有故</el-radio>
					<el-radio v-model="form.malfunctionStatus" label="3">正常</el-radio>
				</el-form-item>
				<el-form-item label="核实情况" prop="failureRemark" style="width: 100%">
					<el-input v-model="form.failureRemark" placeholder="核实情况说明" type="textarea" />
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="submitForm">确 定</el-button>
				<el-button @click="cancel">取 消</el-button>
			</div>
		</el-dialog>
		<el-dialog title="返修任务详情" :visible.sync="openDetail" width="1100px" append-to-body v-dialogDrag>
			<RepairInfo ref="repairdetail" />
		</el-dialog>
		<el-dialog title="上传工艺通知单" :visible.sync="uploadOpen" width="900px" append-to-body v-dialogDrag>
			<el-form ref="uploadform" :model="uploadForm" :rules="uploadRules" label-width="140px" class="add-form1">
				<el-form-item label="工艺通知单编号" prop="processNumber">
					<el-input v-model="uploadForm.processNumber" placeholder="请输入工艺通知单编号" maxlength="20"
						show-word-limit />
				</el-form-item>
				<el-form-item label="工艺通知单">
					<FileUpload @input="getFiles" :value="uploadList" :limit="1"></FileUpload>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="submitFormUpload">确 定</el-button>
				<el-button @click="cancelUpload">取 消</el-button>
			</div>
		</el-dialog>
		<!-- 审批弹框 -->
		<el-dialog title="审批" :visible.sync="openApprove" width="900px" append-to-body v-dialogDrag>
			<ApproveTemplete @cancelApprove="cancelApprove" :openApprove="openApprove"></ApproveTemplete>
		</el-dialog>
		<!-- 审批流程弹框 -->
		<el-dialog title="审批流程" :visible.sync="openRecords" width="900px" append-to-body v-dialogDrag>
			<RecordsTemplete :approveRecord="approveRecord"></RecordsTemplete>
		</el-dialog>
		<el-dialog title="多余物记录列表" :visible.sync="componentOpen" width="900px" append-to-body v-dialogDrag>
			<div style="height: 70vh; overflow-y: auto; padding-right: 15px">
				<el-table :data="compentRecords" style="margin-bottom: 20px" border>
					<el-table-column label="序号" width="55" type="index" />
					<el-table-column label="产品图号" prop="productModel" min-width="150" show-overflow-tooltip="">
					</el-table-column>
					<el-table-column label="产品名称" prop="productName" min-width="120" show-overflow-tooltip="">
					</el-table-column>
					<el-table-column label="数量" prop="quantity" min-width="150" show-overflow-tooltip="" align="center">
					</el-table-column>
					<el-table-column label="操作" class-name="small-padding fixed-width" width="280px" fixed="right"
						align="center">
						<template slot-scope="scope">
							<el-button size="mini" type="text" icon="el-icon-view"
								@click="detailsComponents(scope.row)">详情</el-button>
							<el-button size="mini" type="text" icon="el-icon-edit" @click="workWirte(scope.row)"
								v-hasPermi="['RedundantController:RedundantController:workWirte']">工人填报</el-button>
							<el-button size="mini" type="text" icon="el-icon-edit" @click="checkWirte(scope.row)"
								v-hasPermi="['RedundantController:RedundantController:checkWirte']">检验填报</el-button>
						</template>
					</el-table-column>
				</el-table>
			</div>
		</el-dialog>
		<el-dialog title="修改多余物" :visible.sync="editconponents" width="100%" append-to-body v-dialogDrag>
			<div style="height: 70vh; overflow-y: auto; padding-right: 15px">
				<el-form :model="editRowComponent" size="small" :inline="true" label-width="100px">
					<el-form-item label="产品图号" prop="productModel">
						<el-input v-model="editRowComponent.productModel" placeholder="请输入产品图号" disabled />
					</el-form-item>
					<el-form-item label="产品名称" prop="productName">
						<el-input v-model="editRowComponent.productName" placeholder="请输入产品名称" disabled />
					</el-form-item>
					<el-form-item label="数量" prop="quantity">
						<el-input v-model="editRowComponent.quantity" placeholder="请输入数量" disabled />
					</el-form-item>
				</el-form>
				<el-table ref="writeTable" @mousedown.native="mousedownTables" @cell-mouse-enter="cell_mouse_enters"
					row-key="id" @cell-mouse-leave="cell_mouse_leaves" @mouseup.native="mouseupTables"
					@mouseleave.native="mouseupTables" :data="detailscomponentsList" style="margin-bottom: 20px"
					@row-click="handleRowClick" border @selection-change="handleSelectionRecords">
					<el-table-column type="selection" width="55" align="center" />
					<el-table-column label="工序号" prop="processNumber" min-width="120" align="center" key="1">
						<template slot-scope="scope">
							<el-input-number v-model="scope.row.processNumber" :min="1" :max="10000000"
								style="width: 150px" disabled></el-input-number>
						</template>
					</el-table-column>
					<el-table-column label="工序名称" prop="processName" min-width="120" show-overflow-tooltip=""
						align="center" key="2">
						<template slot-scope="scope">
							<el-input v-model="scope.row.processName" maxlength="200" disabled></el-input>
						</template>
					</el-table-column>
					<el-table-column label="检查结果" prop="conclusion" min-width="180" show-overflow-tooltip=""
						align="center" key="3" v-if="workWirtes">
						<template slot-scope="scope">
							<el-select clearable="" :disabled="looks" v-model="scope.row.conclusion"
								@change="chengResult($event, scope.row)" @blur="chengResult($event, scope.row)">
								<el-option v-for="item in packagRecordList" :key="item.id" :value="item.name"
									:label="item.name"></el-option>
							</el-select>
						</template>
					</el-table-column>
					<el-table-column label="工人" prop="workerId" min-width="120" show-overflow-tooltip="" align="center"
						key="4" v-if="workWirtes">
						<template slot-scope="scope">
							<el-select clearable="" v-model="scope.row.workerId"
								@change="selectComponentusers($event, scope.row)"
								@blur="selectComponentusers($event, scope.row)" :disabled="looks">
								<el-option v-for="item in worksData" :key="item.userId" :value="item.userId"
									:label="item.nickName"></el-option>
							</el-select>
						</template>
					</el-table-column>
					<el-table-column label="工人时间" prop="workerTime" min-width="120" show-overflow-tooltip=""
						align="center" key="5" v-if="workWirtes">
						<template slot-scope="scope">
							<el-date-picker clearable="" @change="selectworkTime($event, scope.row)"
								@blur="selectworkTime($event, scope.row)" :disabled="looks" style="width: 150px"
								v-model="scope.row.workerTime" format="yyyy-MM-dd" value-format="yyyy-MM-dd" type="date"
								placeholder="选择日期"> </el-date-picker>
						</template>
					</el-table-column>
					<el-table-column v-if="checkWirtes" label="检验人" prop="recipientId" min-width="120"
						show-overflow-tooltip="" align="center" key="6">
						<template slot-scope="scope">
							<el-select clearable="" :disabled="looks" v-model="scope.row.recipientId"
								@blur="selectComponentrecipient($event, scope.row)"
								@change="selectComponentrecipient($event, scope.row)">
								<el-option v-for="item in allocatedListData" :key="item.userId" :value="item.userId"
									:label="item.nickName"></el-option>
							</el-select>
						</template>
					</el-table-column>
					<el-table-column v-if="checkWirtes" label="检验时间" prop="recipientTime" min-width="120"
						show-overflow-tooltip="" align="center" key="7">
						<template slot-scope="scope">
							<el-date-picker clearable="" :disabled="looks" @change="selectTimes($event, scope.row)"
								@blur="selectTimes($event, scope.row)" style="width: 150px"
								v-model="scope.row.recipientTime" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
								type="date" placeholder="选择日期"> </el-date-picker>
						</template>
					</el-table-column>
					<el-table-column label="备注" prop="remark" min-width="120" show-overflow-tooltip="" align="center"
						key="8">
						<template slot-scope="scope">
							<el-input v-model="scope.row.remark" maxlength="100" rows="3" :disabled="looks"></el-input>
						</template>
					</el-table-column>
				</el-table>
			</div>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="submitFormcomponents">确 定</el-button>
				<el-button @click="editconponents = false">取 消</el-button>
			</div>
		</el-dialog>
	</div>
</template>
<script>
import { componentList, redundancyEdit, editRecord, listFault, listFaultChild, getFault, editFault, breakdownUp, submitProduction, productionApprove, editFaultMore, RecordList } from "@/api/fault/faultlist"
import RepairInfo from "@/views/components/RepairInfo"
import FileUpload from "@/components/FileUpload"
import CreateForm from "@/views/components/CreateForm"
import { mapGetters } from "vuex"
import { approvalRecord } from "@/api/productTechnology/productTechnologyVersions"
import ApproveTemplete from "@/views/components/ApproveTemplete"
import RecordsTemplete from "@/views/components/RecordsTemplete"
import { getUserList, getworkerList, getcolumn, allocatedList } from "@/api/selectList"
import searchStateMixin from '@/layout/mixin/searchStateMixin.js'   
export default {
	name: "RedundantControllers",
	mixins: [searchStateMixin],   
	dicts: ["default_approve", "fault_status", "maintain_cat"],
	components: { RepairInfo, FileUpload, CreateForm, ApproveTemplete, RecordsTemplete },
	computed: {
		...mapGetters(["sidebar", "name", "id"])
	},
	data() {
		return {
			checkWirtes: false,
			workWirtes: false,
			looks: false,
			recordIds: [],
			recordId: "",
			recordsSection: [],
			packagRecordLists: [
				{
					id: "1",
					name: "下拉框"
				},
				{
					id: "0",
					name: "自行输入"
				}
			],
			packagRecordList: [
				{
					id: "0",
					name: "合格"
				},
				{
					id: "1",
					name: "/"
				}
			],
			isMousedownTables: false, //是否按下表格
			currentEnterRows: null, //当前移入的行数据
			isMousedownTable: false, //是否按下表格
			currentEnterRow: null, //当前移入的行数据
			dragSelect: false,
			startIndex: null,
			endIndex: null,
			worksData: [],
			editRowComponent: {},
			detailscomponentsList: [],
			editconponents: false,
			compentRecords: [],
			componentOpen: false,
			editRowForm: {},
			detailsRecordsList: [],
			editRecords: false,
			usersData: [],
			allocatedListData: [],
			FormRecords: {},
			partRecords: false,
			productRecords: [],
			eleTabTop: 0, //表格容器距浏览器顶部距离
			testval: undefined,
			// 遮罩层
			loading: true,
			// 选中数组
			ids: [],
			rows: [],
			// 非单个禁用
			single: true,
			// 非多个禁用
			multiple: true,
			// 显示搜索条件
		showSearch: true,
			// 总条数
			total: 0,
			// 设备保养计划表格数据
			FaultList: [],
			// 弹出层标题
			title: "",
			// 是否显示弹出层
			open: false,
			// 查询参数
			queryParams: {
				pageNum: 1,
				pageSize: 10,
				repairNumber: undefined,
				malfunctionStatus: undefined,
				productName: undefined,
				productModel: undefined,
				productNumber: undefined
			},
			// 表单参数
			form: {},
			// 表单校验
			rules: {
				malfunctionVerifyTime: [{ required: true, message: "请选择故障日期" }],
				maintenanceCategoryId: [{ required: true, message: "请选择维修类别" }],
				malfunctionStatus: [{ required: true, message: "请选择核实状态" }]
			},
			deviceList: [],
			// 更新树刷新
			treeMap: new Map(),
			disabled: false,
			openDetail: false,
			uploadOpen: false,
			// 上传
			uploadForm: {},
			uploadRules: {
				processNumber: [{ required: true, message: "请输入工艺通知单编号" }]
			},
			uploadList: [],
			treetablekey: Math.random(),
			// 审批数据
			openApprove: false,
			approveRow: undefined,
			// 审批流程
			openRecords: false,
			approveRecord: [],
			// 列信息
			columns: [
				{ key: 0, label: `返修任务单`, visible: true },
				{ key: 1, label: `客户代表`, visible: true },
				{ key: 2, label: `用户`, visible: true },
				{ key: 3, label: `产品名称`, visible: true },
				{ key: 4, label: `产品型号`, visible: true },
				{ key: 5, label: `产品编号`, visible: true },
				{ key: 6, label: `产品数量`, visible: true },
				{ key: 7, label: `核实故障日期`, visible: true },
				{ key: 8, label: `维修类别`, visible: true },
				{ key: 9, label: `故障模式`, visible: true },
				{ key: 10, label: `故障核实情况`, visible: true },
				{ key: 11, label: `状态`, visible: true },
				{ key: 12, label: `工艺通知单编号`, visible: true },
				{ key: 13, label: `审批状态`, visible: true }
			]
		}
	},

	created() {
		// 如果是页面刷新，重置查询
		if (window.performance && performance.navigation.type === performance.navigation.TYPE_RELOAD) {
			this.resetForm("queryForm")
			// 清除URL中的查询参数（不刷新页面）
			window.history.replaceState({}, document.title, window.location.pathname);
		}
		this.getUsers()
		this.getallocatedList()
		this.workData()
		// this.getSize()

	},
	mounted() {
		// 滚动条的获取
		this.handleScrollx()
		window.addEventListener("scroll", this.handleScrollx, true)
	},
	watch: {
		"$route.query": {
			handler(newQuery, oldQuery) {
				if (newQuery.queryData) {
					if (Object.keys(newQuery.queryData).length === 0) {
						this.resetQuerys()
						// this.getSize()
					} else {
						this.queryParams = { ...this.queryParams, ...JSON.parse(newQuery.queryData) }
						// this.getSize()
					}
				}
				this.getSize()
			},
			immediate: true, // 立即执行一次
			deep: true // 深度监听
		}
	},
	activated() {
		// this.workData()
		// this.getUsers()
		// this.getallocatedList()
		// this.getSize()
		//获取表格容器距页面头部的距离
		// this.handleScrollx()
	},
	destroyed() {
		window.removeEventListener("scroll", this.handleScrollx, true)
	},
	methods: {
		getallocatedList() {
			allocatedList().then(res => {
				this.allocatedListData = res.rows
			})
		},
		getSize() {
			getcolumn({ pageName: "Pagination52" }).then(response => {
				this.queryParams.pageSize = response.data.length ? (response.data[0].limit ? response.data[0].limit : 10) : 10
				this.getList()
			})
		},
		detailData(row) {
			this.editRowComponent = row
			if (row.tcomponentRedundancies.length) {
				row.tcomponentRedundancies.forEach((item, index) => {
					item.id = item.id ? item.id : "c1" + index
					item.isdefault = true
				})
			}
			this.detailscomponentsList = row.tcomponentRedundancies.length == 0 ? [{}] : row.tcomponentRedundancies
			this.editconponents = true
		},
		detailsComponents(row) {
			this.workWirtes = true
			this.checkWirtes = true
			this.looks = true
			this.detailData(row)
		},
		workWirte(row) {
			this.looks = false
			this.workWirtes = true
			this.checkWirtes = false
			this.detailData(row)
		},
		checkWirte(row) {
			this.looks = false
			this.checkWirtes = true
			this.workWirtes = false
			this.detailData(row)
		},

		clearData(index, row) {
			this.detailscomponentsList[index].isdefault = !this.detailscomponentsList[index].isdefault
		},
		selectTimes(e, row) {
			let flag1 = this.recordIds.includes(row.id)
			if (this.recordsSection.length && flag1) {
				this.recordsSection.forEach((item, index) => {
					this.recordsSection[index].recipientTime = row.recipientTime
					this.detailscomponentsList.forEach(items => {
						if (item.id == items.id) {
							items.recipientTime = row.recipientTime
						}
					})
				})
			}
		},
		selectComponentrecipient(e, row) {
			var now = new Date()
			var year = now.getFullYear() // 获取当前年份
			var month = now.getMonth() + 1 // 获取当前月份，月份从0开始，所以需要+1
			var day = now.getDate() // 获取当前日期
			let flag1 = this.recordIds.includes(row.id)
			if (row.recipientId) {
				this.allocatedListData.forEach(item => {
					if (row.recipientId == item.userId) {
						row.recipientName = item.nickName
					}
				})
			} else {
				row.recipientTime = undefined
				row.recipientName = undefined
			}

			if (this.recordsSection.length && flag1) {
				this.recordsSection.forEach((item, index) => {
					this.recordsSection[index].recipientId = row.recipientId
					this.recordsSection[index].recipientName = row.recipientName
					this.recordsSection[index].recipientTime = row.recipientId ? (row.recipientTime ? row.recipientTime : year + "-" + month + "-" + day) : undefined
					this.detailscomponentsList.forEach(items => {
						if (item.id == items.id) {
							items.recipientId = row.recipientId
							items.recipientName = row.recipientName
							items.recipientTime = row.recipientId ? (row.recipientTime ? row.recipientTime : year + "-" + month + "-" + day) : undefined
						}
					})
				})
			}
		},
		handleSelectionRecords(selection) {
			this.recordsSection = selection
			this.recordIds = selection.map(item => item.id)
		},
		// 表格按下
		mousedownTables(event) {
			const target = event.target
			// 判断target的class属性确定是否点击在复选框上
			if (target.classList.contains("el-checkbox__inner")) {
				this.currentEnterRows && this.$refs.writeTable.toggleRowSelection(this.currentEnterRows)
				this.isMousedownTables = true
			}
		},

		// 进入单元格
		cell_mouse_enters(row, column, cell, event) {
			this.isMousedownTables && this.$refs.writeTable.toggleRowSelection(row)
			this.currentEnterRows = row
		},
		// 离开单元格
		cell_mouse_leaves(row, column, cell, event) {
			this.currentEnterRows = null
		},
		// 鼠标弹起或者离开表格
		mouseupTables(d) {
			this.isMousedownTables = false
		},

		// 多选框选中数据
		handleSelectionChange(selection) {
			this.ids = selection.map(item => item.id)
			this.rows = selection
			this.single = selection.length !== 1
			this.multiple = !selection.length
		},
		// 表格按下
		mousedownTable(event) {
			const target = event.target
			// 判断target的class属性确定是否点击在复选框上
			if (target.classList.contains("el-checkbox__inner")) {
				this.currentEnterRow && this.$refs.table.toggleRowSelection(this.currentEnterRow)
				this.isMousedownTable = true
			}
		},
		// 单击表格行
		row_click(row, column, event) {
			// this.currentEnterRow || this.$refs.table.toggleRowSelection(row)
			if (column && column.label == "操作") {
				return
			} else {
				this.$refs.table.toggleRowSelection(row)
			}
		},
		changeTableData() {
			this.$nextTick(() => {
				this.$refs.table.doLayout()
			})
		},

		// 进入单元格
		cell_mouse_enter(row, column, cell, event) {
			this.isMousedownTable && this.$refs.table.toggleRowSelection(row)
			this.currentEnterRow = row
		},
		// 离开单元格
		cell_mouse_leave(row, column, cell, event) {
			this.currentEnterRow = null
		},
		// 鼠标弹起或者离开表格
		mouseupTable(d) {
			this.isMousedownTable = false
		},
		// 表格每行样式
		row_class_name({ row, rowIndex }) {
			return this.rows.find(v => v.id == row.id) ? "selected" : ""
		},
		handleRowClick(row, column, event) {
			if ((column && column.label == "检验时间") || (column && column.label == "检验人") || (column && column.label == "检查结果") || (column && column.label == "工人") || (column && column.label == "工人时间") || (column && column.label == "备注")) {
				return
			} else {
				this.$refs.writeTable.toggleRowSelection(row)
			}
		},
		submitFormcomponents() {
			let copyData = JSON.parse(JSON.stringify(this.detailscomponentsList))
			copyData.forEach(item => {
				item.id = String(item.id).includes("c1") ? null : item.id
			})
			this.editRowComponent.tcomponentInspectionRecordDetailList = copyData
			this.editRowComponent.tcomponentRedundancies = copyData
			redundancyEdit(this.editRowComponent).then(res => {
				this.$modal.msgSuccess("修改成功")
				this.editconponents = false
				this.getList()
				localStorage.setItem("todoMessage", "controller5")
			})
		},
		addComponents(row, index) {
			let data = this.detailscomponentsList
			if (data[data.length - 1].processNumber && data[data.length - 1].processName && data[data.length - 1].conclusion && data[data.length - 1].workerId && data[data.length - 1].recipientId && data[data.length - 1].workerTime && data[data.length - 1].recipientTime) {
				data.push({
					remark: undefined,
					processNumber: undefined,
					processName: undefined,
					conclusion: undefined,
					workerId: undefined,
					recipientId: undefined,
					workerTime: undefined,
					recipientTime: undefined
				})
			} else {
				this.$modal.msgError("请将数据填写完整")
			}
		},
		deleteComponents(index, row) {
			this.detailscomponentsList.splice(index, 1)
		},
		chengResult(e, row) {
			console.log(e, row)
			var now = new Date()
			var year = now.getFullYear() // 获取当前年份
			var month = now.getMonth() + 1 // 获取当前月份，月份从0开始，所以需要+1
			var day = now.getDate() // 获取当前日期
			if (row.conclusion) {
				if (!row.workerId) {
					row.workerId = this.id
				}
				if (!row.workerTime) {
					row.workerTime = year + "-" + month + "-" + day
				}
			} else {
				row.workerId = undefined
				row.workerTime = undefined
			}

			let flag1 = this.recordIds.includes(row.id)
			if (this.recordsSection.length && flag1) {
				this.recordsSection.forEach((item, index) => {
					this.recordsSection[index].conclusion = row.conclusion
					this.recordsSection[index].workerId = row.workerId
					this.recordsSection[index].workerTime = row.workerTime
					this.detailscomponentsList.forEach(items => {
						if (item.id == items.id) {
							items.conclusion = row.conclusion
							items.workerId = row.workerId
							items.workerTime = row.conclusion ? (row.workerTime ? row.workerTime : year + "-" + month + "-" + day) : undefined
						}
					})
				})
			}
		},
		selectworkTime(e, row) {
			let flag1 = this.recordIds.includes(row.id)
			if (this.recordsSection.length && flag1) {
				this.recordsSection.forEach((item, index) => {
					this.recordsSection[index].workerTime = row.workerTime
					this.detailscomponentsList.forEach(items => {
						if (item.id == items.id) {
							items.workerTime = row.workerTime
						}
					})
				})
			}
		},
		selectComponentusers(e, row) {
			if (row.workerId) {
				this.worksData.forEach(item => {
					if (e == item.userId) {
						row.workerName = item.nickName
					}
				})
			} else {
				row.workerName = undefined
			}
			let flag1 = this.recordIds.includes(row.id)
			if (this.recordsSection.length && flag1) {
				this.recordsSection.forEach((item, index) => {
					this.recordsSection[index].workerId = row.workerId
					this.recordsSection[index].workerName = row.workerName
					this.detailscomponentsList.forEach(items => {
						if (item.id == items.id) {
							items.workerId = row.workerId
							items.workerName = row.workerName
						}
					})
				})
			}
		},

		selectusers(e, row) {
			this.usersData.forEach(item => {
				if (e == item.userId) {
					row.recipientName = item.nickName
				}
			})
		},

		detailsRecords(row) {
			this.editRowForm = row
			this.detailsRecordsList = row.tcomponentInspectionRecordDetailList.length == 0 ? [{}] : row.tcomponentInspectionRecordDetailList
			this.editRecords = true
		},
		submitFormRecords() {
			this.editRowForm.tcomponentInspectionRecordDetailList = this.detailsRecordsList
			editRecord(this.editRowForm).then(res => {
				this.$modal.msgSuccess("修改成功")
				this.editRecords = false
			})
		},
		addRecords(row, index) {
			let data = this.detailsRecordsList
			if (data[data.length - 1].programTests && data[data.length - 1].conclusion && data[data.length - 1].recipientId) {
				data.push({
					programTests: undefined,
					conclusion: undefined,
					recipientId: undefined,
					remark: undefined
				})
			} else {
				this.$modal.msgError("请将数据填写完整")
			}
		},
		deleteRecords(index, row) {
			// if (this.detailsRecordsList.length > 1) {
			this.detailsRecordsList.splice(index, 1)
			// }
		},

		getUsers() {
			getUserList({
				deptId: 116
			}).then(res => {
				this.usersData = res.rows
			})
		},
		workData() {
			getworkerList().then(res => {
				this.worksData = res.rows
			})
		},
		handleControl(row) {
			componentList({
				repairId: row.id
			}).then(res => {
				res.rows.forEach(item => {
					if (item.tcomponentRedundancies.length == 0) {
						item.tcomponentRedundancies = [{}]
					}
				})
				this.compentRecords = res.rows
				this.componentOpen = true
			})
		},
		//获取表格容器距页面头部的距离
		handleScrollx() {
			this.eleTabTop = this.$refs.eleTab.getBoundingClientRect().top
		},
		/** 查询设备保养计划列表 */
		getList() {
			this.loading = true
			listFault(this.queryParams).then(response => {
				this.FaultList = response.rows
				this.FaultList.forEach((item, index) => {
					item.hasChildren = true
					item.sort = index + 1
					// this.$refs.table.toggleRowExpansion(item, false)
				})
				this.total = response.total
				this.loading = false
			})
		},
		// 获取列表详情
		async loadListDes(tree, treeNode, resolve) {
			if (!this.treeMap.has(tree.id)) {
				this.treeMap.set(tree.id, {
					treeNode,
					resolve
				})
			}
			let queryParams = JSON.parse(JSON.stringify(this.queryParams))
			delete queryParams.pageSize
			delete queryParams.pageNum
			let data = {
				id: tree.id,
				...queryParams
			}
			let ret = await listFaultChild(data)
			ret.rows.forEach((item, index) => {
				// 父子id会冲突
				item.id = "c" + item.id
				item.sort = index + 1
			})
			resolve(ret.rows)
		},
		// 取消按钮
		cancel() {
			this.open = false
			this.$refs.table.clearSelection()
			this.reset()
		},
		// 表单重置
		reset() {
			this.form = {
				repairId: undefined,
				repairNumber: undefined,
				productName: undefined,
				productModel: undefined,
				processNumber: undefined,
				productNumber: undefined,
				receiptTime: undefined,
				malfunctionVerifyTime: undefined,
				maintenanceCategoryId: undefined,
				maintenanceCategoryName: undefined,
				failureMode: undefined,
				malfunctionStatus: undefined,
				failureRemark: undefined
			}
			this.resetForm("form")
		},
		/** 搜索按钮操作 */
		handleQuery() {
			this.queryParams.pageNum = 1
			this.saveSearchState()  
			this.getList()
			this.treetablekey = Math.random()
		},
		resetQuerys() {
			this.queryParams = {
				pageNum: 1,
				pageSize: this.queryParams.pageSize,
				repairNumber: undefined,
				malfunctionStatus: undefined,
				productName: undefined,
				productModel: undefined,
				productNumber: undefined
			},
				this.resetForm("queryForm")
		},
		/** 重置按钮操作 */
		resetQuery() {
			this.queryParams = {
				pageNum: 1,
				pageSize: this.queryParams.pageSize,
				repairNumber: undefined,
				malfunctionStatus: undefined,
				productName: undefined,
				productModel: undefined,
				productNumber: undefined
			},
				this.resetForm("queryForm")
				this.clearSearchCache()   
			this.handleQuery()
		},

		// 详情
		handleDetailChild(row) {
			this.disabled = true
			this.reset()
			const id = row.id.replace("c", "")
			getFault(id).then(response => {
				this.form = response.data
				this.open = true
				this.title = "故障核实"
				// this.form.malfunctionStatus = "2"
				this.$nextTick(() => {
					this.$refs.form.clearValidate()
				})
			})
		},
		// 更改维修类别
		changeCat() {
			let cur = this.dict.type.maintain_cat.find(ele => {
				return ele.value == this.form.maintenanceCategoryId
			})
			this.form.maintenanceCategoryName = cur.label
		},
		/** 提交按钮 */
		submitForm() {
			this.$refs["form"].validate(valid => {
				if (valid) {
					const loading = this.$loading({
						lock: true,
						text: "Loading",
						spinner: "el-icon-loading",
						background: "rgba(0, 0, 0, 0.7)"
					})
					if (this.form.id == 0) {
						// 批量
						editFaultMore(this.form)
							.then(response => {
								this.$modal.msgSuccess("操作成功")
								this.$refs.table.clearSelection()
								this.open = false
								loading.close()
								// 刷新树
								this.treeMap.forEach((item, idx) => {
									this.loadListDes({ id: idx }, item.treeNode, item.resolve)
								})
								localStorage.setItem("todoMessage", "controller1")
							})
							.catch(err => {
								loading.close()
							})
					} else {
						// 单个
						editFault(this.form)
							.then(response => {
								this.$modal.msgSuccess("操作成功")
								this.$refs.table.clearSelection()
								this.open = false
								loading.close()
								let treeObj = this.treeMap.get(this.form.repairId)
								this.loadListDes({ id: this.form.repairId }, treeObj.treeNode, treeObj.resolve)
								localStorage.setItem("todoMessage", "controller2")
							})
							.catch(err => {
								loading.close()
							})
					}
				}
			})
		},
		// 返修单详情详情
		handleDetail(row) {
			this.openDetail = true
			this.$nextTick(() => {
				this.$refs.repairdetail.resetFormData(row.id)
			})
		},
		// 表单上传工艺通知单重置
		uploadReset(formids) {
			this.uploadForm = {
				productIds: formids,
				fileList: [],
				processNumber: undefined
			}
			this.uploadList = []
			this.resetForm("uploadform")
		},
		submitFormUpload() {
			this.$refs["uploadform"].validate(valid => {
				if (valid) {
					if (this.uploadList.length == 0) {
						this.$modal.msgError("请先上传文件")
						return false
					}
					this.uploadForm.fileList = this.uploadList
					breakdownUp(this.uploadForm).then(response => {
						this.$modal.msgSuccess("操作成功")
						this.uploadOpen = false
						// 刷新树
						this.treeMap.forEach((item, idx) => {
							this.loadListDes({ id: idx }, item.treeNode, item.resolve)
						})
						// 清空已选
						this.$refs.table.clearSelection()
						localStorage.setItem("todoMessage", "controller2")
					})
				}
			})
		},
		cancelUpload() {
			this.$refs.table.clearSelection()

			this.uploadOpen = false
		},

		// 审批
		handleApprove(row) {
			this.openApprove = true
			this.approveRow = row
		},

		// 审批取消
		async cancelApprove(ret) {
			if (!ret.flag) {
				this.openApprove = false
				return false
			}
			let id = this.approveRow.id.replace("c", "")
			let data = {
				approvalStatus: ret.approvalStatus,
				causeRejection: ret.causeRejection,
				id: id,
				workflowType: "11"
			}
			let res = await productionApprove(data)
			if (res.code == 200) {
				this.$modal.msgSuccess("操作成功")

				// 刷新树
				this.treeMap.forEach((item, idx) => {
					this.loadListDes({ id: idx }, item.treeNode, item.resolve)
				})
				this.$refs.table.clearSelection()
				localStorage.setItem("todoMessage", "controller4")
			}
			this.openApprove = false
		},
		// 获取审批详情
		showApproveList(row) {
			if (row.malfunctionApprovalStatus == "0") {
				return false
			}
			this.openRecords = true
			let id = row.id.replace("c", "")
			approvalRecord({
				id: id,
				workflowType: "11"
			}).then(res => {
				this.openRecords = true
				this.approveRecord = res.data
			})
		},
		// 列表附件
		handleAnnex(row) {
			this.$router.push({
				path: "/attachment/attachmentUpload",
				query: {
					TableId: row.id,
					typeId: 11,
					perm: "RedundantController:RedundantController:annex",
					// queryParams: JSON.stringify(this.queryParams),
					paths: "/RedundantController/RedundantController",
				}
			})
		},
		// 产品附件
		handleAnnex2(row) {
			let id = row.id.replace("c", "")
			this.$router.push({
				path: "/attachment/attachmentUpload",
				query: {
					TableId: id,
					typeId: 12,
					perm: "RedundantController:RedundantController:annex2",
					// queryParams: JSON.stringify(this.queryParams),
					paths: "/RedundantController/RedundantController",
				}
			})
		},
		truncateAtLastDecimal(str) {
			return str.replace(/(\.\d+)?$/, "")
		},
		// 上传
		getFiles(files) {
			this.uploadList = files
			var fileNameWithoutExtension = files[0].fileName.split(".").slice(0, -1).join(".")
			this.uploadForm.processNumber = fileNameWithoutExtension
		}
	}
}
</script>

<style lang="scss" scoped>
// 列表计划名称左对齐，标题居中
.form-title {
	width: 100%;
	height: 3rem;
	padding-left: 1rem;

	.title-msg {
		padding-bottom: 0.8rem;
		border-bottom: 2px solid rgb(42, 130, 228);
	}
}

::v-deep .el-table__fixed-header-wrapper .fixed-width {
	width: 240px !important;
}
</style>
